<template>
	<view>
    <view class="list">
      <view v-for="(item,index) in list" class="item" :key="index">
        <view>
          <view class="flex" style="margin-bottom: 10rpx;">
             <view class="title"><span v-if="item.type==0">投诉</span>
             <span v-if="item.type==1">建议</span></view>
             <view class="time">{{item.createTime}}</view>
          </view>
          <view>
            <view>{{item.content}}</view>
            <view class="img " v-if="item.imgs">
              <image mode="" v-for="(item1,idx) in item.imgs.split(',') "  :src="item1" :key="idx" style="margin-right: 5px;" @tap="preview(item.imgs.split(','),idx)"></image>
            </view>
          </view>
          <view v-if="item.state==1">
            {{item.platformReply}}
          </view>
         </view>
         <view style="display: flex;justify-content: flex-end;">
           <view class="bnt" @tap="del(item.id)">删除</view>
         </view>
      </view>
    </view>
	</view>
</template>

<script setup>
  const picUrl = import.meta.env.VITE_APP_RESOURCES_URL
	 const list  = ref([])
   const current = ref(1)
   const pages = ref(0)
   onShow(() => {
     getlist(current.value)
   })
   onReachBottom(() => {
     if (current.value < pages.value) {
       getlist( current.value + 1)
     }
   })
 const del = (id) => {
     uni.showLoading()
     http.request({
       url: '/p/user/complaintSuggestions/'+id,
       method: 'DELETE',
       data:{}
     })
       .then(({ data }) => {
         console.log(data)
         current.value=1
         getlist(current.value)
          uni.hideLoading()
       })
   }
   const preview=(list,idx)=>{
     uni.previewImage({ 
       urls:list, //可以展示imgUrl 列表中所有的图片
       current: idx //首先当前index对应图片，左右可以切换其他序号的图片
      });
   }
   const getlist = (currentParam) => {
     uni.showLoading()
     http.request({
       url: '/p/user/complaintSuggestions/page',
       method: 'GET',
       data: {
         current: currentParam,
         size: 10,
       }
     })
       .then(({ data }) => {
         console.log(data)
         let listParam = []
         if (data.current === 1) {
           listParam = data.records
         } else {
           listParam = list.value
           Array.prototype.push.apply(listParam, data.records)
         }
         list.value = listParam
         pages.value = data.pages
         current.value = data.current
         uni.hideLoading()
       })
   }
</script>

<style  scoped lang="scss">
  .list{
    padding: 20rpx 30rpx;
    .item{
      padding: 20rpx;
      border-bottom: 1px solid #eee;
    }
  }
  .flex{
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 26rpx;
    .title{
      font-size: 30rpx;
    }
    .time{
      color: #999;
      font-size: 24rpx;
    }
  }
  .img{
    display: flex;
    align-items: center;
    image{
      width:150rpx;
      height: 150rpx;
      margin: 10rpx ;
    }
  }
  .bnt{
    width:120rpx ;
    padding: 8rpx 0;
    background: #3a86b9;
    text-align: center;
    color: #fff;
    font-size: 26rpx;
    border-radius: 38rpx;
  }
</style>
